﻿using AutoMapper;

namespace GroceryPriceBook.Core.Mappers
{
	/// <summary>
	/// View Model object for presentation which inherits the AutoMapper Profile class
	/// </summary>
	public class ProductCategory : Profile
	{
		public override string ProfileName
		{
			get { return "ProductCategoryMappings"; }
		}

		protected override void Configure()
		{
			Mapper.CreateMap<Model.ProductCategory, ViewModel.ProductCategory>()
				  .ForMember(dest => dest.ParentProductCategoryId, opt => opt.MapFrom(src => src.ParentCategoryId))
				  .ForMember(dest => dest.ProductCategories, opt => opt.MapFrom(src => src.ProductCategory1))
				  .ForMember(dest => dest.ParentProductCategory, opt => opt.MapFrom(src => src.ProductCategory2));
			Mapper.CreateMap<ViewModel.ProductCategory, Model.ProductCategory>()
				  .ForMember(dest => dest.ParentCategoryId, opt => opt.MapFrom(src => src.ParentProductCategoryId))
				  .ForSourceMember(src => src.Products, opt => opt.Ignore())
				  .ForSourceMember(src => src.ProductCategories, opt => opt.Ignore())
				  .ForSourceMember(src => src.ProductCategorySelectListItems, opt => opt.Ignore())
				  .ForSourceMember(src => src.ParentProductCategory, opt => opt.Ignore());
		}
	}
}
